package cn.xs.goods.dao.impl;


import java.util.List;

import org.apache.commons.dbutils.handlers.BeanListHandler;

import cn.xs.core.dao.impl.BaseDaoImpl;
import cn.xs.goods.dao.CategoryDao;
import cn.xs.goods.entity.Category;

public class CategoryDaoImpl extends BaseDaoImpl<Category> implements CategoryDao {


	public void save(Category entity) {
		try{
			String sql = "insert into t_category values(?,?,?,?);";
			Object[] params = {entity.getId(),entity.getName(),entity.getDescription(),entity.getParent_id()};
			getQueryRunner().update(sql, params);
		}catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	public List<Category> findParentsCategory() {
		try{
			String sql ="select * from t_category where parent_id is null;";
			return (List<Category>) getQueryRunner().query(sql, new BeanListHandler(Category.class));
		}catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	public List<Category> findCategorysByPid(String pid) {
		try{
			String sql ="select * from t_category where parent_id = '"+pid+"';";
			return (List<Category>) getQueryRunner().query(sql, new BeanListHandler(Category.class));
		}catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	
}
